package com.goldsprite.gdxcore.utils.math;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

public class Vector2Int extends Vector2 implements AutoCloseable {
	private static final int POOL_SIZE = 1024;
	private static final BlockingQueue<Vector2Int> pool = new ArrayBlockingQueue<>(POOL_SIZE);

	public int intX, intY;

	public Vector2Int() {
		this(0, 0);
	}

	public Vector2Int(Vector2 vec) {
		this(vec.getX(), vec.getY());
	}

	public Vector2Int(Vector2Int vec) {
		this(vec.getX(), vec.getY());
	}

	public Vector2Int(float x, float y) {
		setX(x);
		setY(y);
	}


	public Vector2Int(int x, int y) {
		setX(x);
		setY(y);
	}

	public static Vector2Int obtain() {
		return obtain(0, 0);
	}

	public static Vector2Int obtain(int x, int y) {
		Vector2Int v = pool.poll();
		if (v == null) {
			v = new Vector2Int();
		}
		v.setX(x);
		v.setY(y);
		v.inUse = true;
		return v;
	}

	public float getX() {
		return intX;
	}

	public void setX(float x) {
		super.x = this.intX = (int) x;
	}

	public float getY() {
		return intY;
	}

	public void setY(float y) {
		super.y = this.intY = (int) y;
	}

	@Override
	public String toString() {
		return String.format("{%d, %d}", intX, intY);
	}

	public Vector2 toVector2() {
		return this;
	}

	@Override
	public void close() {
		if (inUse) {
			inUse = false;
			if (pool.size() < POOL_SIZE) {
				pool.offer(this);
			}
		}
	}
}
